﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SMP_QuanLySV.DAL;
using SMP_QuanLySV.BLL;

namespace SMP_QuanLySV.Presentation
{
    public partial class UC_DoiPass : UserControl
    {
        frmMain parent;
        BLLUserManager usm;

        // constructor
        public UC_DoiPass(frmMain parent)
        {
            InitializeComponent();
            this.parent = parent;
            usm = new BLLUserManager();
            txtTenUser.Text = UIManager.currentUserName;
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            if (txtConfirm.Text != txtPassMoi.Text)
            {
                MessageBox.Show("Lặp lại password mới không đúng", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (usm.checkValid(UIManager.currentUserName, txtPassCu.Text))
                {
                    UIManager.currentUserPass = txtPassMoi.Text;
                    if (usm.updatePass(UIManager.currentUserName, UIManager.currentUserPass))
                    {
                        MessageBox.Show("Bạn đã đổi password thành công", "Congratulation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtPassCu.Enabled = false;
                        txtPassMoi.Enabled = false;
                        txtConfirm.Enabled = false;
                    }
                }
                else
                {
                    MessageBox.Show("Password cũ không đúng", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

    }
}
